<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<title>地图</title>		
	<script src="../dist/scripts/libs/jquery.min.js"></script>
	<script src="../dist/scripts/libs/init.js"></script>
</head>
<body>
	<header class="ub ub-ac">
		<div class="leftBtn click">
			<p class="left"></p>
		</div>
		<div class="ub-f1 ut-s tx-c title">地图</div>
		<div class="rightBtn"></div>
	</header>
	<article class="map ub ub-ver">
		<div id="tip"></div>
		<div id="mapContainer" class="ub-f1"></div>
  	</article>
</body>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=4291ec579c5ee4e2a2aef36f4ba3e6f1"></script>
<script>
     //自定义定位标记
    function getMap(x, y){
        var lnglatXY = [x, y];
        var marker = new AMap.Marker({
            position: lnglatXY
        });
        //初始化地图对象，加载地图
        var map = new AMap.Map('mapContainer', {
            zoom: 13,
            isHotspot: true,
            center: lnglatXY,
            resizeEnable: true
        });
        marker.setMap(map);
        AMap.service('AMap.Geocoder',function(){//回调函数
            //实例化Geocoder
            var geocoder = new AMap.Geocoder({
                // city: "010"//城市，默认：“全国”
            });
            geocoder.getAddress(lnglatXY, function(status, result) {
                if (status === 'complete' && result.info === 'OK') {
                    // var city = result.regeocode.addressComponent.city;
                    $('#tip').text(result.regeocode.formattedAddress);
                }else{
                    alert('无法获取街道信息');
                }
            });  
        });
    }
$(function(){
	$(".map").height($(window).height());
	if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position){
            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;
            getMap(longitude, latitude);
            // setTimeout(function(){
            //     location.href = 'http://m.amap.com?q=' + latitude + ',' + longitude + '&amp;name=王大锤';
            // },2000);
        },function(error){
            // alert(error.code + "----------" + error.message);
            alert(error.message);
        });
    }else{
        alert("定位失败,请检查是否开启定位");
    }
});
</script>	
</html>

